package android.activities;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Database;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class BasesActivity extends ListActivity implements OnClickListener {
	
	Database database;
	List<String> items;
	TextView text;
	View view;
	int _item = 0;
	
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	database = new Database(this);
    	items = database.getBasesNames();
        setListAdapter(new ArrayAdapter<String>(this, R.layout.bases, items));
        final ListView listview = getListView();
        registerForContextMenu(listview); 
        listview.setOnItemClickListener(new OnItemClickListener() {
    	public void onItemClick(AdapterView<?> parent, View _view, int _position, long id) {   		
    		 _item = _position;
    		 _item++;
    		Intent i = new Intent(BasesActivity.this, LoginActivity.class);
    		i.putExtra(LoginActivity.KLUCZ, String.valueOf(_item));
    		startActivity(i);
    	}
    	});
    }
   
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	super.onCreateOptionsMenu(menu);
    	MenuInflater inf = getMenuInflater();
    	inf.inflate(R.menu.menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem element)
    {
    	switch (element.getItemId())
    	{
    	case R.id.dodaj:
    		Intent i = new Intent(BasesActivity.this, NewBaseActivity.class); 		
    		startActivity(i);
    		return true;
    	}
    	return false;
    }

	public void onClick(View v) {		
		
	} 
}
